package models

import (
	"social-app/dao"
	"time"
)

type UserLogger struct {
	Id         int       `json:"id"`
	UserId     int       `json:"user_id"`
	Type       int       `json:"type"`
	Ip         string    `json:"ip"`
	CreateTime time.Time `json:"create_time" gorm:"autoCreateTime"`
	UpdateTime time.Time `json:"update_time" gorm:"autoUpdateTime"`
}

func (UserLogger) TableName() string {
	return "user_logger"
}

func WriteUserLoginLogger(userId int, ip string) (UserLogger, error) {
	userLogger := UserLogger{
		UserId: userId,
		Type:   1,
		Ip:     ip,
	}
	err := dao.Db.Create(&userLogger).Error
	return userLogger, err
}
